import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ProblemManagement from '../component/Teacher/ProblemManagement/ProblemManagement.vue'
import ExamManagement from '../component/Teacher/ExamManagement/ExamManagement.vue'
import ScoreManagement from '../component/Teacher/ScoreManagement/ScoreManagement.vue'
import ExamList from '../component/student/ExamList/ExamList.vue'
import MyExam from '../component/student/MyExam/MyExam.vue'
import BeginExam from '../component/student/ExamList/BeginExam.vue'
import ScoremDetails from '../component/Teacher/ScoreManagement/Scoredetails.vue'
import MyDetail from '../component/student/MyExam/MyDetail.vue'
import store from '../store/index'
Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
},
{
    path: '/detail',
    name: 'detail',
    component: MyDetail,
},
{
    path: '/home',
    name: 'home',
    component: HomeView
},
{
    path: '/beginexam',
    name: 'beginexam',
    component: BeginExam
},
{
    path: "/problemmanagement",
    name: "problemmanagement",
    component: ProblemManagement
},
{
    path: "/exammanagement",
    name: "exammanagement",
    component: ExamManagement
},
{
    path: "/scoremanagement",
    name: "scoremanagement",
    component: ScoreManagement,

},
{

    path: '/Scoremdetails',
    name: 'Scoremdetails',
    component: ScoremDetails

},
{
    path: "/examlist",
    name: "examlist",
    component: ExamList
},
{
    path: "/myexam",
    name: "myexam",
    component: MyExam
}
]
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {
    console.log(to);
    if (to.path === '/home') {
        store.state.flag = false
        console.log(store.state.flag);
        next()
    } else if (to.path === '/beginexam') {
        store.state.flag = false
        console.log(store.state.flag);
        next()
    } else {
        store.state.flag = true
        console.log(store.state.flag);
        next()
    }
})

export default router